package top.igotcha;

/**
 * @author Gotcha
 * @date 2021/3/22
 * @describe 加锁懒汉
 */
public class Singleton01 {
    private static Singleton01 SINGLETON = null;

    private Singleton01() {
    }

    public static synchronized Singleton01 getInstance(){
        if (SINGLETON != null){
            return SINGLETON;
        }
        SINGLETON = new Singleton01();
        return SINGLETON;
    }
}
class test01{
    public static void main(String[] args) {
        String a = new String("aaa");
        String intern = a.intern();
        String b = "aaa";
        System.out.println(b==intern);
        Singleton01 singleton01a = Singleton01.getInstance();
        Singleton01 singleton01b = Singleton01.getInstance();
        System.out.println(singleton01a.equals(singleton01b));
    }
}
